﻿<Window x:Class="MissedMemo.MeatAndCheeseDisc.OrderEntry.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="clr-namespace:MissedMemo.MeatAndCheeseDisc.OrderEntry"
    Title="(caption set at run time)"
    Icon="/OrderEntryUI;component/Resources/Application.ico"
    Height="640" Width="500">

    <Window.Resources>
        <ResourceDictionary>

            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="resOrderTemplates.xaml" />
            </ResourceDictionary.MergedDictionaries>

            <Style x:Key="OrdersListBorderStyle" TargetType="Border" >
                <Setter Property="Background" Value="{StaticResource brushListBackground}" />
                <Setter Property="BorderBrush" Value="{StaticResource brushListBorder}" />
                <Setter Property="BorderThickness" Value="2" />
                <Setter Property="CornerRadius" Value="6" />
                <Setter Property="Margin" Value="8" />
            </Style>

        </ResourceDictionary>
    </Window.Resources>
    
    
    <Window.CommandBindings>
        <CommandBinding Command="ApplicationCommands.Save" Executed="OnSaveChanges" />
        <CommandBinding Command="ApplicationCommands.Delete" Executed="OnDelete" />
    </Window.CommandBindings>
    
    
    <Grid Background="{StaticResource brushMainWindow}" >
        <Border Style="{StaticResource OrdersListBorderStyle}" >

            <Grid Name="layoutRoot" DataContext="{x:Static local:App.OrderCollection}" >

                <Grid.RowDefinitions>
                    <RowDefinition Height="auto" />
                    <RowDefinition Height="*" />
                </Grid.RowDefinitions>

                <!-- "Add" button looks like list item (but can't be scrolled) -->
                <Button Grid.Row="0" Content="Add New Order" Click="OnAddOrder" Margin="4,4,4,3" >
                    <Button.Template>
                        <ControlTemplate TargetType="Button" >
                            <Border Style="{StaticResource AddOrderButtonStyle}">
                                <ContentPresenter VerticalAlignment="Center" />
                            </Border>
                        </ControlTemplate>
                    </Button.Template>
                </Button>

                <ListBox Grid.Row="1" Name="listOrders" ItemsSource="{Binding}"
                         HorizontalContentAlignment="Stretch"
                         ItemTemplate="{StaticResource OrderTemplate}"
                         BorderBrush="{x:Null}" Background="{x:Null}"
                         IsSynchronizedWithCurrentItem="True">
                    
                    <ListBox.ItemContainerStyle>
                        <Style TargetType="ListBoxItem">
                            <Style.Resources>
                                <!-- Cancel selected item blue border -->
                                <SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="Transparent"/>
                                <SolidColorBrush x:Key="{x:Static SystemColors.ControlBrushKey}" Color="Transparent"/>
                            </Style.Resources>
                            <EventSetter Event="MouseLeftButtonUp" Handler="listOrders_MouseLeftButtonUp" />
                            <!-- Line up with "Add" button -->
                            <Setter Property="Margin" Value="0,0,2,3" />
                        </Style>
                    </ListBox.ItemContainerStyle>

                </ListBox>
                
            </Grid>           
        </Border>
        
        <!-- EditPanel floats OVER TOP OF underlying list, buttons, etc. -->
        <local:viewOrderEditPanel x:Name="OrderEditPanel" Height="0" Width="auto" />
        
    </Grid>
    
</Window>
